package thread.api;


import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import static thread.api.utils.ThreadUtils.sleep;

/**
 * @author ykh
 */

@Log4j2
public class FutureTaskTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建任务对象
        FutureTask<Integer> task3 = new FutureTask<>(() -> {
            log.debug("hello");
            return 100;
        });

        // 参数1 是任务对象; 参数2 是线程名字，推荐
        new Thread(task3, "t3").start();

        // futureTask.get()会导致主线程阻塞，同步等待 task 执行完毕的结果
        Integer result = task3.get();

        log.debug("结果是:{}", result);

    }


}
